package com.mm.dss.demo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mm.dss.demo.adapter.Myhttpadapter;
import com.mm.dss.demo.base.BaseActivity;

import static com.mm.dss.demo.tools.Constances.imgulr;

public class XxCjinfoActivity extends BaseActivity {
    private TextView txt_title;
    private RelativeLayout layout_back;
    private TextView taskname;//信息采集点
    private TextView cjr;//采集人
    private TextView time;//采集时间
    private TextView taskinfo;//采集信息
    private LinearLayout lineartu;//总的图片布局，当图片为null的时候不显示，默认不显示
    private RecyclerView img_recycler_view;//图片布局
    private String tp="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xx_cjinfo);
        initview();
        initdata();
    }
    private void initview() {
        taskinfo= (TextView) findViewById(R.id.taskinfo);
        txt_title= (TextView) findViewById(R.id.txt_title);
        txt_title.setText("信息采集详情");
        layout_back= (RelativeLayout) findViewById(R.id.layout_back);
        layout_back.setVisibility(View.VISIBLE);
        taskname= (TextView) findViewById(R.id.taskname);
        cjr= (TextView) findViewById(R.id.cjr);
        time= (TextView) findViewById(R.id.time);
        lineartu= (LinearLayout) findViewById(R.id.lineartu);
        img_recycler_view= (RecyclerView) findViewById(R.id.img_recycler_view);
        img_recycler_view.setLayoutManager(new GridLayoutManager(this,9));
    }
    private void initdata() {
        taskname.setText("采 集 点："+getIntent().getStringExtra("jcd"));
        taskinfo.setText(getIntent().getStringExtra("xcxx"));
        time.setText("采集时间："+getIntent().getStringExtra("time"));
        cjr.setText("采 集 人："+getIntent().getStringExtra("cjr"));
        tp=getIntent().getStringExtra("tp");
        if (!tp.equals("")){
            lineartu.setVisibility(View.VISIBLE);
            final String[] sourceStrArray = tp.split(",");
            for (int i = 0; i < sourceStrArray.length; i++) {
                sourceStrArray[i]=imgulr+sourceStrArray[i];
                System.out.println(sourceStrArray[i]);
                Log.i("img的值",sourceStrArray[i]+"");
            }
            Myhttpadapter myadapter = new Myhttpadapter(sourceStrArray, XxCjinfoActivity.this);
            img_recycler_view.setAdapter(myadapter);
            myadapter.setItemListener(new Myhttpadapter.onRecyclerItemClickerListener() {
                @Override
                public void onItemClick(View view, String[] strlist, int i) {
                    Intent intent = new Intent();
                    intent.putExtra("imageUrls", sourceStrArray);
                    intent.putExtra("curImageUrl", sourceStrArray[i]);
                    intent.putExtra("tasktype", 0);//这个页面这个值没什么用，主要是为了在下个页面区分是否是任务详情页面跳转的
                    intent.setClass(XxCjinfoActivity.this, PhotoBrowserActivity.class);
                    startActivity(intent);
                }
            });
        }else {
            lineartu.setVisibility(View.GONE);
        }
    }
    public void onclick(View view){
        switch (view.getId()){
            case R.id.layout_back:
                finish();
                break;
        }
    }

}
